package cn.biplam.front.component.view.systemManage.sysprivi.privilege.deploy.add;

import cn.biplam.common.client.DataFilter;
import cn.biplam.common.client.Operator;
import cn.biplam.common.client.OperatorResult;
import cn.biplam.common.opcode.SysManageCode.PriviDeployOptCode;
import cn.biplam.common.struc.SysStruc.PriviDeployStruc;
import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.KvMap;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.ComponentBase;
import cn.biplam.front.component.view.systemManage.sysprivi.privilege.PriviDeployManage;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.htmlscript.script.AjxScript;
import cn.biplam.front.template.base.Input;
import cn.biplam.front.template.complex.InputPrompt;

/**
 *  添加和修改权限大类
 * @author XiaoRuxing Dec 7, 20099:44:21 AM
 * @version 1.0
 */
public class PriviDeployAdd extends ComponentBase{

	private static final String cId = PriviDeployManage.cId;
	
	public PriviDeployAdd(UserInfo user, String homeUrl, String recordId,
			KvMap<String, String> params) {
		super(user, homeUrl, recordId, params);
	}

	/**
	 * @return 添加权限大类界面
	 */
	public HtmlWindow addPanel() throws ErrorMessage{
		InputPrompt prompt = new InputPrompt(PriviDeployManage.Privi_Deploy_Add_Submit,
				recordId,cId+"add");
		HtmlWindow win = panel(prompt, recordId);
		return win;
	}
	
	/**
	 * 添加权限大类数据提交
	 * @return 刷新脚本
	 */
	public HtmlWindow add() throws ErrorMessage{
		DataFilter filter = new DataFilter();
		filter.putAll(params);
		Operator.get(PriviDeployOptCode.Insert, mUser.getUserID(), filter);
		HtmlWindow win = new HtmlDiv();
		win.bind(AjxScript.getA(PriviDeployManage.Privi_Deploy_Main, //刷新容器ID
				PriviDeployManage.Privi_Deploy_Main,					 //刷新动作ID
				"add"
				));
		return win;
	}
	
	/**
	 * @return 修改权限大类界面
	 */
	public HtmlWindow editPanel() throws ErrorMessage{
		InputPrompt prompt = new InputPrompt(PriviDeployManage.Privi_Deploy_Edit_Submit,
				recordId,cId+"edit");
		HtmlWindow win = panel(prompt, recordId);
		return win;
	}
	
	/**
	 *  修改权限大类数据提交
	 * @return 刷新脚本
	 * @throws ErrorMessage 
	 */
	public HtmlWindow edit() throws ErrorMessage{
		DataFilter filter = new DataFilter(recordId);
		filter.putAll(params);
		Operator.get(PriviDeployOptCode.Edit, mUser.getUserID(), filter);
		HtmlWindow win = new HtmlDiv();
		win.bind(AjxScript.getA(PriviDeployManage.Privi_Deploy_Main, //刷新容器ID
				PriviDeployManage.Privi_Deploy_Main,					 //刷新动作ID
				"edit"
				));
		return win;
	}
	
	/**
	 *  
	 * @return 权限大类编辑界面
	 */
	private HtmlWindow panel(InputPrompt prompt,String recordId) throws ErrorMessage{
		String priviName = null;
		String priviDesc = null;
		String enterAction = null;
		DataFilter filter = new DataFilter(recordId);
		OperatorResult operatorResult = Operator.get(PriviDeployOptCode.Qurey_By_ID, mUser.getUserID(), filter);
		if(TOOLS.exist(operatorResult)){
			priviName = operatorResult.getValue(PriviDeployStruc.NAME);
			priviDesc = operatorResult.getValue(PriviDeployStruc.DESC);
			enterAction = operatorResult.getValue(PriviDeployStruc.SHOW_ACT_ID);
		}
		//设置输入内容
		prompt.putTh("名称", 0, 0);
		prompt.putTd(new Input(null,PriviDeployStruc.NAME,priviName,20,40).get(), 0, 1);
		prompt.putTh("说明", 1, 0);
		prompt.putTd(new Input(null,PriviDeployStruc.DESC,priviDesc,20,200).get(), 1, 1);
		prompt.putTh("入口交换码", 2, 0);
		prompt.putTd(new Input(null,PriviDeployStruc.SHOW_ACT_ID,enterAction,15).get(), 2, 1);
		prompt.setColSize(2, 0, 10);
		//设置输入检查项
		prompt.putCheckItem(PriviDeployStruc.NAME, "权限类型名称不能为空!");
		prompt.putCheckItem(PriviDeployStruc.SHOW_ACT_ID, "入口交换码不能为空!");
		return prompt.get();
	}
	
}
